package cola0502.project.hellospringbootcola0502.controller;

import cola0502.project.hellospringbootcola0502.event.ColaEvent;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
@Api(tags = "ColaController")
@RestController
@Slf4j
@RequestMapping("/v1/api/colas")
public class ColaController {

    @Resource
    ApplicationContext context;

    @ApiOperation("sayHelloGet")
    @GetMapping("sayHelloGet")
    public String sayHelloGet() {
        log.info("访问到：{}","sayHelloGet");
        return "HelloCola-Get";
    }

    @ApiOperation("sayHelloPost")
    @PostMapping("sayHelloPost")
    public String sayHelloPost() {
        return "HelloCola-Post";
    }
    @ApiOperation("sayHelloDelete")
    @DeleteMapping("sayHelloDelete")
    public String sayHelloDelete() {
        return "HelloCola-Delete";
    }
    @ApiOperation("colaListener")
    @GetMapping("colaListener")
    public String colaListener() {
        context.publishEvent(new ColaEvent("colaListener was get"));
        return "colaListener";
    }
}
